package src.percolation;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TreeMap;

import src.utils.Utils;

public class Pr_1_d_averaging {



	public static void main(String[] argvs) throws Exception {

		int netSize;

		double minProba;
		double maxProba;
		double eps;


		try {
			netSize = new Integer(argvs[0]);
			minProba = new Double(argvs[1]);
			maxProba = new Double(argvs[2]);
			eps = new Double(argvs[3]);

		} catch (Exception e) {
			showUsage();
			return;
		}



		double probability;
		Random gen = new Random();
		int trials = 50;
		for(probability = minProba;probability<maxProba;probability += eps) {
	
			//average over many trials on the same probability
			for(int i=0;i<trials;i++){
				long seed = gen.nextLong();
				Red myRed = new Red(netSize,seed);
				myRed.createGrid(probability);
				Map<Integer,Integer> clusterHistogram = myRed.clusterHistogram();
				
				Utils.printToFile(clusterHistogram, "A"+(int)Math.floor(probability*1000)+"-"+i+".dat");
			}

		}	
	}
	private static void showUsage() {
		System.out.println("Usage: ");

		System.out.println("<netSize> <minProba> <maxProba> <increment> <eps> <meanOutFile> <sigmaOutFile>\n");

		System.out.println("<netSize>: size of net.");
		System.out.println("<minProba>: minimum probability.");
		System.out.println("<maxProba>: maximum probability.");
		System.out.println("<increment>: increment between probabilities.");

	}
}

	
